using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPMasterOrdersService
    {
        ISession session;

        public MRPMasterOrdersService(ISession session)
        {
            this.session = session;
        }
        public MRPMasterOrdersService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpmasterorders(MRPMasterOrders mrpmasterordersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpmasterordersX);
            tx.Commit();
        }

        public void UpdateMrpmasterorders(MRPMasterOrders mrpmasterordersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpmasterordersX);
            tx.Commit();
        }

        public void DeleteMrpmasterorders(MRPMasterOrders mrpmasterordersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpmasterordersX);
            tx.Commit();
        }

        public IList<MRPMasterOrders> GetAllMrpmasterorders(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPMasterOrders");
            IList<MRPMasterOrders> list = query.List<MRPMasterOrders>();
            if (evict)
            {
                foreach (MRPMasterOrders s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPMasterOrders GetAllMrpmasterordersByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPMasterOrders as c where c.Masterordercode= :x");
            query.SetString("x", id);
            MRPMasterOrders s = (MRPMasterOrders)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPMasterOrders> GetMrpmasterordersByQuery(IQuery query, Boolean evict)
        {
            IList<MRPMasterOrders> list = query.List<MRPMasterOrders>();
            if (evict)
            {
                foreach (MRPMasterOrders s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
